Page({
  data: {
      address_id: null,
      name: "",
      mobile: "",
      school:"",
      class:"",
      detail: "",

  },
  onLoad: function (e) {
    console.log(e,'编辑onload')
      getApp().page.onLoad(this, e);
      var t = this;
      t.setData({
          address_id: e.id,
      })
      // e.id && (getApp().core.showLoading({
      //     title: "正在加载",
      //     mask: !0
      // })
  
      // );
  },
  saveAddress: function () {
      var t = this;
      console.log(t,'学校')
      if (!this.data.name) {
          wx.showToast({
            title: '请填写姓名',
            icon: 'none'
          })
          return
      }
      if (!this.data.mobile) {
          wx.showToast({
            title: '请填写联系电话',
            icon: 'none'
          })
          return
      }
      if (!this.data.school) {
          wx.showToast({
            title: '请填写学校',
            icon: 'none'
          })
          return
      }
      if (!this.data.class) {
          wx.showToast({
            title: '请填写班级',
            icon: 'none'
          })
          return
      }
      if (!(/^1[3456789]\d{9}$/.test(this.data.mobile))) {
          wx.showToast({
            title: '联系电话不是正确的手机号',
            icon: 'none'
          })
          return
      }
     
      getApp().core.showLoading({
          title: "正在保存",
          mask: !0
      });
   
      
      getApp().request({
          url: getApp().api.user.address_save,
          method: "post",
          data: {
              address_id: t.data.address_id || "",
              name: t.data.name,
              mobile: t.data.mobile,
              school:t.data.school,
              class:t.data.class,
              // province_id: e.province.id,
              // city_id: e.city.id,
              // district_id: e.district.id,
              // detail: t.data.detail + t.data.house_number,
              // longitude: t.data.longitude,
              // latitude: t.data.latitude,
              // is_default: t.data.is_default
          },
          success: function (e) {
              getApp().core.hideLoading(), 0 == e.code && 
              getApp().core.showModal({
                  title: "提示",
                  content: e.msg,
                  showCancel: !1,
                  success: function (e) {
                      e.confirm && getApp().core.navigateBack();
                  }
              })
               1 == e.code && wx.showToast({
                  title: e.msg,
                  icon: 'none'
              });
          }
      });
  },
  inputBlur: function (e) {
      console.log(e,'input')
      var t = '{"' + e.currentTarget.dataset.name + '":"' + e.detail.value + '"}';
      this.setData(JSON.parse(t));
  },
  onShow: function () {
      getApp().page.onShow(this);
  },
  switchChange: function (e) {
      this.setData({
          is_default: e.detail.value ? 1 : 0
      })
  },
  
});